<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });
        });
    </script>
</head>
<body>
<form id="myForm" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td><input type="text" name="name" value="陆小凤"/></td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">身份证号</td>
            <td><input type="text" name="idCard" value="21324324324"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">挂号费</td>
            <td><input type="text" name="regPrice" value="5"/>元</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">社保号</td>
            <td><input type="text" name="medical" value="453253453"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">联系电话</td>
            <td><input type="text" name="phone" value="13543235678"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">是否自费</td>
            <td><input type="radio" name="selfPrice" id="no" value="1"/>否&nbsp;&nbsp;&nbsp;<input type="radio"
                                                                                                  name="selfPrice"
                                                                                                  id="yes" value="0"/>是
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">性别</td>
            <td><input type="radio" name="sex" id="nan" value="0"/>男&nbsp;&nbsp;&nbsp;<input type="radio" name="sex"
                                                                                             id="nv" value="1"/>女
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">年龄</td>
            <td><input type="text" name="age" value="33"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">职业</td>
            <td><input type="text" name="work" value="狗仔队"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">初复诊</td>
            <td><input type="radio" name="lookDoctor" id="first" value="0"/>初诊&nbsp;&nbsp;&nbsp;<input type="radio"
                                                                                                       name="lookDoctor"
                                                                                                       id="second"
                                                                                                       value="1"/>复诊
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">所挂科室</td>
            <td><select name="keShi">
                <option value="0">急诊科</option>
                <option value="1">骨科</option>
                <option value="2">血液科</option>
                <option value="3">外科</option>
            </select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">指定医生</td>
            <td><select name="doctorName">
                <option value="0">程俊</option>
                <option value="1">欧阳雨露</option>
                <option value="2">王博</option>
                <option value="3">沈青川</option>
            </select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><textarea name="remark" id="remark">此人疑拟有精神病</textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button id="update" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button
                        type="button" class="btn btn-success" name="backid" id="backid">返回列表
                </button>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    String.prototype.GetValue = function (para) {
        let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?") + 1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    $(function () {
        let url = document.location.toString();//获取URL
        let id = url.GetValue("id");
        console.log(id);
        let pageNum = url.GetValue("realPageNum");
        let pageSize = url.GetValue("pageSize");
        queryById(id);

        $("#update").click(function () {
            $.ajax({
                type: "POST",//这里必须写POST
                url: "/registration/update/" + id,
                data: $("#myForm").serialize() + "&_method=PUT",
                dataType: "json",
                success: function (vo) {
                    if (vo.code == 200) {
                        window.location.href = "index.html";
                    } else {
                        alert("更新失败！" + vo.msg);
                    }
                }
            });
        });
    });

    function queryById(id) {

        $.ajax({
            type: "GET",
            url: "/registration/id/" + id, //RESTful风格的API定义
            data: "",
            success: function (vo) {
                let obj = vo.obj;
                let id = obj.id;
                let name = obj.name;
                let idCard = obj.idCard;
                let regPrice = obj.regPrice;
                let medical = obj.medical;
                let phone = obj.phone;
                let selfPrice = obj.selfPrice;
                if (selfPrice == 0)
                    $("#yes").attr('checked', true);
                else
                    $("#no").attr('checked', true);
                let sex = obj.sex;
                if (sex == 0)
                    $("#nan").attr('checked', true);
                else
                    $("#nv").attr('checked', true);
                let age = obj.age;
                let work = obj.work;
                let lookDoctor = obj.lookDoctor;
                if (lookDoctor == 0)
                    $("#first").attr('checked', true);
                else
                    $("#second").attr('checked', true);
                let remark = obj.remark;
                let realDoctorName = obj.doctor.name;
                let doctorName = -1;
                if (realDoctorName == '程俊')
                    doctorName = 0;
                if (realDoctorName == '欧阳雨露')
                    doctorName = 1;
                if (realDoctorName == '王博')
                    doctorName = 2;
                if (realDoctorName == '沈青川')
                    doctorName = 3;
                let realKeShi = obj.doctor.keShi;
                let keShi = -1;
                if (realKeShi == '急诊科')
                    keShi = 0;
                if (realKeShi == '骨科')
                    keShi = 1;
                if (realKeShi == '血液科')
                    keShi = 2;
                if (realKeShi == '外科')
                    keShi = 3;
                $("input[name='name']").val(name);
                $("input[name='idCard']").val(idCard);
                $("input[name='regPrice']").val(regPrice);
                $("input[name='medical']").val(medical);
                $("input[name='phone']").val(phone);
                $("input[name='age']").val(age);
                $("input[name='work']").val(work);
                $("select[name='keShi']").val(keShi);
                $("select[name='doctorName']").val(doctorName);
                $("#remark").html(remark);
            }
        });
    }

</script>